﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SiteFox.Business.Manager
{
    public static class BlogCategory
    {
        public static IList<Model.BlogCategory> GetByBlog(int _ID)
        {
            var _Entities = new Model.Entities(Data.WebConfig.GetConnectionString());
            var _Query = from c in _Entities.BlogCategory where c.ID_Blog == _ID orderby c.Title select c;
            return _Query.ToList();
        }
        public static Model.BlogCategory GetByID(int _ID)
        {
            var _Entities = new Model.Entities(Data.WebConfig.GetConnectionString());
            var _Query = from c in _Entities.BlogCategory where c.ID == _ID select c;
            if (_Query.Count() > 0)
            {
                return _Query.Single();
            }
            else
            {
                return null;
            }
        }
        public static void Create(Model.BlogCategory _BlogCategory)
        {
            var _Entities = new Model.Entities(Data.WebConfig.GetConnectionString());
            _Entities.AddToBlogCategory(_BlogCategory);
            _Entities.SaveChanges();
        }
        public static void Edit(Model.BlogCategory _BlogCategory)
        {
            var _Entities = new Model.Entities(Data.WebConfig.GetConnectionString());
            var _Query = from c in _Entities.BlogCategory where c.ID == _BlogCategory.ID select c;
            var __BlogCategory = _Query.Single();
            __BlogCategory.Created = _BlogCategory.Created;
            __BlogCategory.CreatedBy = _BlogCategory.CreatedBy;
            __BlogCategory.Description = _BlogCategory.Description;
            __BlogCategory.ID_Blog = _BlogCategory.ID_Blog;
            __BlogCategory.Modified = _BlogCategory.Modified;
            __BlogCategory.ModifiedBy = _BlogCategory.ModifiedBy;
            __BlogCategory.Title = _BlogCategory.Title;
            _Entities.SaveChanges();
        }
        public static void Delete(int _ID)
        {
            var _Entities = new Model.Entities(Data.WebConfig.GetConnectionString());
            var _Query = from c in _Entities.BlogCategory where c.ID == _ID select c;
            var _BlogCategory = _Query.Single();
            _Entities.BlogCategory.DeleteObject(_BlogCategory);
            _Entities.SaveChanges();
        }
    }
}
